<%
this.adminPage = 'invite';
%>
<% include admin_header %>
<table class="ui center aligned celled table">
<thead>
  <tr>
    <th>用户类型</th>
    <th>邀请码</th>
  </tr>
</thead>

<tbody>
  <% for (let i = 0; i < data.length; i++) { %>
    <tr>
      <td><%= data[i].name %></td>
      <td><%= data[i].code %></td>
    </tr>
  <% } %>
</tbody>
</table>

<div class="ui form">
  <div class="two fields">
    <div class="field">
      <label>用户类型</label>
      <input type="text" id="add_name">
    </div>
    <div class="field">
      <label>邀请码</label>
      <input type="text" id="add_code">
    </div>
  </div>
  <div style="text-align: center; "><div id="add_button" class="ui submit blue labeled icon button"><i class="ui add icon"></i>添加</a></div>
</div>

<form method="post" id="submit_form">
  <input type="hidden" name="data" id="submit_data">
</form>

<script>
var data = [];
<% for (let i = 0; i < data.length; i++) { %>
  data.push("<%= data[i].code %>");
<% } %>

$('#add_button').click(function () {
  if(data.indexOf($('#add_name').val()) > -1 || data.indexOf($('#add_code').val()) > -1) {
    $("#submit_from").append('<div class="ui page dimmer"><div class="content"><div class="center">类型或邀请码已存在！</div></div></div>');
    return;	
  }
  $('#submit_data').val(JSON.stringify({ name: $('#add_name').val(), code: $('#add_code').val() }));
  $('#submit_form').submit();
});
</script>
<% include admin_footer %>
